package edu.ycu.aladdin.collector.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import edu.ycu.aladdin.collector.api.entity.weibo.Tab;
import edu.ycu.aladdin.collector.api.entity.weibo.UserInfo;

import java.util.List;

/**
 * @author <a href="mailto:wangruihuano@gmail.com">王瑞环</a>
 * @since 2019-04-15 15:28
 */
public class ParseUtils {

    /**
     * 用户信息解析
     * @param json
     * @return
     */
    public static UserInfo parseUserInfoFromJson(String json){

        JSONObject jsonObject = JSON.parseObject(json);
        JSONObject data = jsonObject.getJSONObject("data");
        UserInfo userInfo = data.getJSONObject("userInfo").toJavaObject(UserInfo.class);
        JSONArray tabsJson = data.getJSONObject("tabsInfo").getJSONArray("tabs");
        List<Tab> tabs = tabsJson.toJavaList(Tab.class);
        userInfo.setTabs(tabs);

        return userInfo;
    }

    // TODO 微博页数据解析
}
